package ru.urfc.portal.ui.client.googlets.client;

import ru.urfc.portal.ui.client.BaseGooglet;
import ru.urfc.portal.ui.client.descriptor.GridDescriptor;
import ru.urfc.portal.ui.client.descriptor.GridField;
import ru.urfc.portal.ui.client.model.catalogs.DeviceState;
import ru.urfc.portal.ui.client.widgets.MegaGrid;

import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Element;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiTemplate;
import com.google.gwt.user.client.ui.Widget;

public class NetDeviceList extends BaseGooglet {

	@UiTemplate("RegularList.ui.xml")
	interface Binder extends UiBinder<Widget, NetDeviceList> {}
	private static Binder binder = GWT.create(Binder.class);

	@UiField MegaGrid grid;
	@UiField Element title;

	@Override
	protected void init() {
		initWidget(binder.createAndBindUi(this));
		title.setInnerText("РЭС на этой радиосети");
		
		GridDescriptor descriptor = new GridDescriptor(DEVICE, CLIENTS, getClientId(), NETS, getItemId(), DEVICES);
		GridField autoExpandColumnField = createColumns(descriptor);
		descriptor.addCIColumn("state/text", "state/code", DeviceState.class, "Статус", 100);
		
		createController(descriptor, grid);
        grid.setAutoExpandColumn(autoExpandColumnField.getName());
        grid.setWidth(400);
	}

	static public GridField createColumns(GridDescriptor descriptor) {
		GridField autoExpandColumnField = 
		descriptor.addAnchorColumn("type/name", "id", PAGE_DEVICE_DETAILS, "Тип", 100);
		descriptor.addTextColumn("number", "Заводской №", 100);
		descriptor.addTextColumn("nChannels", "Каналов", 50);
		descriptor.addIntColumn("watts", "Мощность", 70).getIntRenderer().setWattsFormat();
		return autoExpandColumnField;
	}
	
}